<?php
namespace App\Http\Controllers;

use App\Models\Act;
use App\Models\ActPrize;
use App\Models\ActWinners;
use App\Models\ActWinnersInfo;
use Illuminate\Http\Request;
class ActWinnersController extends CommonController
{

    /**
     *获取列表
     */
    public function getIndex()
    {
        $lists = ActWinners::with('user','act', 'prizeArray.prize')->orderBy('created_at', 'desc')->paginate(10);
        return view('actwinners.index')->with("lists", $lists)->with("actions", $this->actions);
    }

    /**
     * 执行一个搜索
     */
    public function search(Request $request)
    {
        $data = $request->input();

        $lists = ActWinners::orderBy('created_at', 'desc');

        if (isset($data['act_title']) && $data['act_title'] != '') {
            $actIds = Act::where('title', 'like', '%'.trim($data['act_title']).'%')->lists('id');
            $lists->whereIn('act_id', $actIds);
        }

        if (isset($data['prize_title']) && $data['prize_title'] != '') {
            $prizeIds = ActPrize::where('name', 'like', '%'.trim($data['prize_title']).'%')->lists('id');
            $lists->whereIn('prize_id', $prizeIds);
        }


        if (isset($data['username']) && $data['username'] != '') {
            $lists->where('username', 'like', '%'.trim($data['username']).'%');
        }

        if (isset($data['tel']) && $data['tel'] != '') {
            $lists->where('tel', 'like', '%'.trim($data['tel']).'%');
        }

        $lists = $lists->paginate(10);


        return view('actwinners.search')->with("lists", $lists)->with("actions", $this->actions)
            ->with("act_title", trim($data['act_title']))->with("prize_title", trim($data['prize_title']))
            ->with("username", trim($data['username']))->with("tel", trim($data['tel']));
    }

    /**
     * 获取创建页面
     */
    public function getCreate()
    {
    }

    /**
     * 执行一个创建
     */
    public function postCreate()
    {
    }

    /**
     * 获取编辑页面
     */
    public function getEdit(Request $request)
    {
        $data = $request->input();

        $list = ActWinners::where('id', $data['id'])->with('user','winnerInfo','act', 'prize')->first();

        return view('actwinners.edit')->with("list", $list);
    }

    /**
     * 执行一个编辑
     */
    public function postEdit(Request $request)
    {
        $data = $request->input();
    }


}